public class Board {

	private int currentPlayer = 0;
	private int playerCount;
	private Player players[];
	private int[] tokens;
	private String[] playerNames;
	private String errorMessage;
	private Dice dice = new Dice();
	private int activePlayers;
	
	private static boolean ignoreGo = false;
	
	public int getActivePlayers() {
	
		return activePlayers;
	}

	public void setActivePlayers(int activePlayers) {
		
		this.activePlayers = activePlayers;
	}

	public static boolean getIgnoreGo() {
		
		return ignoreGo;
	}

	public static void setIgnoreGo(boolean ignoreGo) {
		
		Board.ignoreGo = ignoreGo;
	}

	public Dice getDice() {
	
		return dice;
	}

	public void setDice(Dice dice) {
		
		this.dice = dice;
	}

	public int getCurrentPlayer() {
	
		return currentPlayer;
	}

	public void setCurrentPlayer(int currentPlayer) {
		
		this.currentPlayer = currentPlayer;
	}

	public String getErrorMessage() {
	
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		
		this.errorMessage = errorMessage;
	}

	public String[] getPlayerNames() {
		
		return playerNames;
	}

	public void setPlayerNames(String[] playerNames) {
		
		this.playerNames = playerNames;
	}
	
	public String getPlayerName(int x) {
		
		return playerNames[x];
	}

	public void setPlayerName(String playerNames, int x) {
		
		this.playerNames[x] = playerNames;
	}

	public void setPlayerCount(int playerCount) {
	
		this.playerCount = playerCount;
	}
	
	public int getPlayerCount() {
	
		return playerCount;
	}

	public Player[] getPlayers() {
		
		return players;
	}

	public void setPlayers(Player[] players) {
		
		this.players = players;
	}
	
	public Player getPlayer(int x) {
		
		return players[x];
	}

	public void setPlayer(Player players, int x) {
		
		this.players[x] = players;
	}

	public int[] getTokens() {
		
		return tokens;
	}

	public void setTokens(int[] tokens) {
		
		this.tokens = tokens;
	}
	
	public int getToken(int x) {
		
		return tokens[x];
	}

	public void setToken(int tokens, int x) {
		
		this.tokens[x] = tokens;
	}
	
	public boolean errorToken() {
		
		for (int x = 0; x < playerCount; x++) {
			
			for (int y = x+1; y < playerCount; y++) {
				
				if (this.getToken(x) == this.getToken(y)) {
					
					errorMessage = "Players cannot have the same token.";
					return true;
				}
			}		
		}	
	
		return false;
	}
	
	public boolean errorName() {
		
		for (int x = 0; x < playerCount; x++) {
			
			if (this.getPlayerName(x).equals("")) {
				errorMessage = "Do not leave field(s) blank.";
				return true;
			}
			
			for (int y = x+1; y < playerCount; y++) {
				
				if (this.getPlayerName(x).equals(this.getPlayerName(y))) {
					
					errorMessage = "Players cannot have the same name.";
					return true;
				}
			}		
		}
		
		return false;
	}
	
	public void putData() {
		
		for (int x = 0; x < playerCount; x++) {
			
			players[x] = new Player(this.getPlayerName(x), this.getToken(x));
		}
	}
		
	public boolean sortPlayers() {
		
		boolean sameRoll = false;
		
		for (int x = 0; x < this.getPlayerCount(); x++) {
						
			for (int y = 1; y < this.getPlayerCount(); y++) {
				
				Dice dice1 = players[y-1].getInitialRoll();
				Dice dice2 = players[y].getInitialRoll();
				
				if (dice1 == dice2) {
					
					sameRoll = true;
				}
				
				if (dice1.getSum() < dice2.getSum()) {
										
					Player t = players[y-1];
					players[y-1] = players[y];
					players[y] = t;
				}
			}
		}
		
		return sameRoll;
	}
	
	public void setLocation() {
		
		for(int x = 0; x < this.getPlayerCount(); x++) {
			
			players[x] = Location.setStartingLocation(players[x], x);
		}
	}
	
	public void nextPlayer() {
		
		do {
		
			if (this.getCurrentPlayer() < this.getPlayerCount()-1) {
				
				this.setCurrentPlayer(this.getCurrentPlayer()+1);
			}
			
			else {
				
				this.setCurrentPlayer(0);
			}
		}
		
		while (this.getPlayer(this.getCurrentPlayer()).isOut() == true);
	}
}